<?php
function regex($data, $regexPattern, $arrayNo)
{
    $regexp = $regexPattern;
    for ($i = 0; $i <= count($matches); $i++) {
        if (preg_match_all("|$regexp|siU", $data, $matches)) {
            return ($matches[$arrayNo]);
        }
    }
}
/*
 * Read webpage source code and return it
 */ 
function curlGetWebPage($url)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}
/*
 * Get All Links from the url as an array
 */
function getLinksFromUrl($url){
    $data = curlGetWebPage($url);
    $regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
    if (preg_match_all("/$regexp/siU", $data, $matches)) {
        return $matches[0];
    }  
}

/**
 * getAllLinksFromText()
 * 
 * @param mixed $input
 * @param mixed $matchesNo
 * @return
 */
function getAllLinksFromText($input, $matchesNo)
{
    $regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
    if (preg_match_all("/$regexp/siU", $input, $matches)) {
        return $matches[$matchesNo];
    }
}
/**
* @param $databasePath: the database path of sqlite
* @param $query: the Select query you want to do
* @return the number of records
*/
function sqliteNumRows($databasePath, $query){
        $dbhandle = sqlite_open($databasePath);
        $query1 = sqlite_query($query,$dbhandle, SQLITE_ASSOC, $query_error); #Lists all tables
        $rows = sqlite_num_rows($query1);
        return $rows;
}

function sqliteNumRowsDbHandle($databasePath, $query){
        $dbhandle = $databasePath;
        $query1 = sqlite_query($query,$dbhandle, SQLITE_ASSOC, $query_error); #Lists all tables
        $rows = sqlite_num_rows($query1);
        return $rows;
}
?>